package cn.hua.trip.base.service.impl;

import cn.hua.trip.base.domain.Strategy;
import cn.hua.trip.base.mapper.StrategyMapper;
import cn.hua.trip.base.query.StrategyQueryObject;
import cn.hua.trip.base.service.IStrategyService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StrategyServiceImpl implements IStrategyService{
    @Autowired
    private StrategyMapper strategyMapper;


    @Override
    public Strategy get(Long id) {
        return strategyMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageInfo list(StrategyQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Strategy> list = strategyMapper.selectSessionCommends(qo);
        return new PageInfo(list);
    }

    @Override
    public List<Strategy> list() {
        return  strategyMapper.selectAll();
    }

    @Override
    public void saveOrUpdate(Strategy strategy) {
        if (strategy.getId()==null) {
            strategyMapper.insert(strategy);
        }else{
            strategyMapper.updateByPrimaryKey(strategy);
        }
    }

    @Override
    public PageInfo query(StrategyQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Strategy> list = strategyMapper.selectForList(qo);
        return new PageInfo(list);
    }
}
